package net.caidingke.shepherd.utils.constant;


import java.util.Arrays;
import java.util.Objects;

/**
 * @author bowen
 */
public enum Type {
    /**
     * product type
     */
    PRODUCT_TYPE(1, "type");

    private final int value;
    private final String name;

    Type(final int value, final String name) {
        this.value = value;
        this.name = name;
    }

    public static Type nameFrom(final String productName) {
        return Arrays.stream(Type.values())
                .filter(type -> Objects.equals(type.name, productName))
                .findFirst()
                .orElse(null);
    }

    public static Type valueFrom(int value) {
        return Arrays.stream(Type.values())
                .filter(type -> type.value == value)
                .findFirst()
                .orElse(null);
    }

    public static void main(String[] args) {
        System.out.println(Type.nameFrom("type"));
        System.out.println(Type.valueFrom(1));
    }
}
